<template>
    <div class="modal fade" id="resetAuditModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
      <div class="modal-dialog">
        <div class="modal-content">
          	<div class="modal-header">
            	<button type="button" class="close" @click="canel"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
            	<h4 class="modal-title" id="myModalLabel">重置报备状态</h4>
          	</div>
          	<div class="modal-body">
          	 	<div class="form-horizontal">
          	 		<div class="form-group">
	                  <label class="col-sm-3 control-label">审核结果：</label>
						<div class="col-sm-9">
							<select class="form-control" v-model="params.customerStatus">
								<option v-for="customerStatus in customerStatusList" :value="customerStatus.value" :key="customerStatus.value">{{ customerStatus.label }}</option>
							</select>
						</div>
	                </div>
					<div class="form-group" v-if="params.customerStatus==6">
						<label class="col-sm-3 control-label">实际到访时间：</label>
						<div class="col-sm-4" >
							<DatePicker type="datetime" :disabled="editVisitTime" placeholder="实际到访时间" v-model="params.createTime" style="width: 200px"></DatePicker>
						</div>
						<div class="col-sm-4">
							<button class="btn pull-right o-color saveAndNext"  @click="editVisitTime = false">修改实际到访时间</button>
						</div>
					</div>

					<div class="form-group" v-if="adviserList.length > 0">
						<label class="col-sm-3 control-label">置业顾问：</label>
						<div class="col-sm-9">
							<select class="form-control" v-model="params.adviserUuid">
								<option v-for="adviser in adviserList" :value="adviser.adviserUuid" :key="adviser.adviserUuid">{{ adviser.name }}</option>
							</select>
						</div>
					</div>
	                <div class="form-group">
	                  <label for="" class="col-sm-3 control-label">备注信息：</label>
	                  <div class="col-sm-9">
	                    <textarea rows="5" class="form-control" v-model="params.remark" placeholder="请填写备注信息"></textarea>
	                  </div>
	                </div>
					<div class="form-group">
	                  <label for="" class="col-sm-3 control-label">上传图片：</label>
	                  <div class="col-sm-9">
						<uploadFile v-bind:uploadState="fileFlag" v-on:fileList='handleAge' :key="resetAuditModal.id"></uploadFile>
					  </div>
	                </div>
	            </div>
          	</div>
          	<div class="modal-footer">
            	<button type="button" class="btn checkedBtn"  @click="save">确定</button>
				<button type="button" class="btn btn-default" @click="canel">取消</button>
          	</div>
        </div>
      </div>
    </div>
</template>

<script>
	import uploadFile from '../uploadFile/uploadFile.vue'
	import {API, Log, Utils, Service} from '../../js/base'
	export default{
		//接收父组件的绑定值
		props: ["resetAuditModal"],
		data() {
			return {
				//机构信息对象
				params: {
				    id:'',
                    customerStatus:'',
					createTime : new Date(),
					adviserUuid: '',
					remark: '',
				},
				imgesList:[],
				fileFlag:true,
				editVisitTime:true,
				adviserList: [],
				customerStatusList: [
					{label: '待审核', value: '0'},
					{label: '未到访', value: '10'},
					{label: '已到访', value: '6'},
					{label: '报备无效', value: 'a'},
					{label: '到访无效', value: 'b'}
				]
			}
		},
		watch:{
        },
		components: {
			uploadFile
		},
		methods: {
            save: function() {
				const _self = this;
				// 若未点击修改实际到访时间则以保存审核结果的时间为准
				if (_self.editVisitTime) {
					_self.params.createTime = new Date();
				}
                if(_self.resetAuditModal.customerStatus != 6){
                    _self.params.createTime = '';
                }

            	if(!_self.params.customerStatus){
            		layer.msg("请选择审核结果", { icon: 7, time: 2000 });
            		return false;
				}
				
                const url = this.utilHelper.apiUrl+'/api/resetAudit';
                const body = {};
                _self.params.id = this.resetAuditModal.id;
				body.params = _self.params;
				body.params.affixList=this.imgesList;
                _self.$http.post(url,body).then((response) =>{
                    const res = response.body.resData;
                    if(res.result == '1') {
                        layer.msg("重置成功!");
						$('#resetAuditModal').modal('hide');
						_self.fileFlag=false;
						_self.imgesList=[];
                        _self.$emit('resetListener');
                    }else {
						layer.msg("重置失败: " + res.resultMsg, { icon: 7, time: 5000 })
                    }
                },(response)=>{
                    layer.msg("系统异常");
                });
			},
			handleAge(data) {
				if(data == '1'){
					this.fileFlag=true;
				}else{
					this.imgesList=data
				}
			},
			canel:function(){
				$('#resetAuditModal').modal('hide');
				this.fileFlag=false;
            },
			init:function(){
                this.params= {
					id:'',
					remark: '',
					customerStatus: '',
					createTime : new Date(),
					adviserUuid: ''
                };
                if(this.resetAuditModal.customerStatus== 6){
                    this.params.createTime = new Date();
                }
			   this.editVisitTime=true;
			   this.getAdviserList();
			},
			getAdviserList() {
				const _this = this
				let id = _this.resetAuditModal.premisesId;
                _this.adviserList = []
                if(!id) return
				Service.Adviser.getAdviserList(id, _this).then(list => {
					if (list && list.length) {
						_this.adviserList = list;
					}
				}).catch(e => {
				})
			}
		}
	}
</script>